﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JoinParty.BLL;
using ZHDJ.WebPage;
using ZHDJ.Data.Models.Org;
using ZHDJ.Data.Models.JoinParty;

namespace JoinParty.Template
{
    public partial class TJoinStep08 : TemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            WordBusiness.Export(this, palWord, "入党积极分子登记表.doc");
        }

        public void LoadData()
        {
            litBranchName.Text = PartyOrgBranch.GetBranchBId(PartyJoinApplycation.BranchID).Rows[0]["BranchName"].ToString();
            litUserName.Text = PartyJoinApplycation.UserName;
            litUserName2.Text = PartyJoinApplycation.UserName;
            litGender.Text = PartyOrgMember.Gender == "0" ? "男" : "女";
            litNation.Text = PartyOrgMember.Nation;
            litBirthday.Text = Convert.ToDateTime(PartyOrgMember.Birthday).ToString("yyyy-MM-dd");
            litNativePlace.Text = PartyOrgMember.NativePlace;
            litBirthplace.Text = PartyOrgMember.Birthplace;
            litEducational.Text = PartyOrgMember.Educational;
            litTitle.Text = PartyOrgMember.Title;

            var stand = DB.PartyJoinLinkExamples.Where(s => s.AppllicationID == PartyJoinApplycation.AppllicationID && s.Status == 1 && s.CurrentStepID == "JoinStep8")
                .OrderByDescending(s => s.CreateTime).FirstOrDefault();
            if (stand == null)
            {
                //FineUI.PageContext.RegisterStartupScript(FineUI.Alert.GetShowReference("未找到相应流程！", "提示"));
                return;
            }
            string activistsId = partyJoinPartyActivists.GetActivistsIDByStandID(stand.StandID);
            var oModel = DB.partyJoinPartyActivistss.Find(activistsId);
            litWorkUnit.Text = oModel.PresentOccupation;
            litApplyTime.Text = PartyJoinApplycation.GetApplyTimeByLoginID(PartyJoinApplycation.LoginID);
            litAddress.Text = PartyOrgMember.Address;
            litCultureTime.Text = oModel.CultureTime?.ToString("yyyy-MM-dd");

            litIdentityCard.Text = PartyOrgMember.IdentityCard;
            litExpertise.Text = PartyOrgMember.Expertise;

            var Contact = DB.partyJoinContacta.Where(a => a.AppllicationID == this.AppllicationID && a.ContactType == 0).ToList();
            if (Contact != null)
            {
                var CulturePeople = "";
                foreach (var item in Contact)
                {
                    CulturePeople += item.ContactName + "、";
                }
                this.litCulturePeople.Text = CulturePeople.Substring(0, CulturePeople.Length - 1);
            }

            var om = DB.PartyOrgMembers.Where(o => o.BranchID == PartyJoinApplycation.BranchID && o.Post == "1").FirstOrDefault();
            if (om != null)
                litBranchSecretary.Text = om.UserName;

            var resume = DB.PartyJoinProbationaryResumes.Where(r => r.ActivistsID == activistsId);
            if (resume != null)
            {
                var resume1 = resume.Where(r => r.OrderNo == 0).FirstOrDefault();
                if (resume1 != null)
                {
                    LiteralOne1.Text = resume1.StartTime;
                    LiteralOne2.Text = resume1.EndTime;
                    LiteralOne3.Text = resume1.Where;
                    LiteralOne4.Text = resume1.Witness;
                    var resume2 = resume.Where(r => r.OrderNo == 1).FirstOrDefault();
                    if (resume2 != null)
                    {
                        LiteralTwo1.Text = resume2.StartTime;
                        LiteralTwo2.Text = resume2.EndTime;
                        LiteralTwo3.Text = resume2.Where;
                        LiteralTwo4.Text = resume2.Witness;
                        var resume3 = resume.Where(r => r.OrderNo == 2).FirstOrDefault();
                        if (resume3 != null)
                        {
                            LiteralThree1.Text = resume3.StartTime;
                            LiteralThree2.Text = resume3.EndTime;
                            LiteralThree3.Text = resume3.Where;
                            LiteralThree4.Text = resume3.Witness;
                            var resume4 = resume.Where(r => r.OrderNo == 3).FirstOrDefault();
                            if (resume4 != null)
                            {
                                LiteralFour1.Text = resume4.StartTime;
                                LiteralFour2.Text = resume4.EndTime;
                                LiteralFour3.Text = resume4.Where;
                                LiteralFour4.Text = resume4.Witness;
                                var resume5 = resume.Where(r => r.OrderNo == 4).FirstOrDefault();
                                if (resume5 != null)
                                {
                                    LiteralFive1.Text = resume5.StartTime;
                                    LiteralFive2.Text = resume5.EndTime;
                                    LiteralFive3.Text = resume5.Where;
                                    LiteralFive4.Text = resume5.Witness;
                                    var resume6 = resume.Where(r => r.OrderNo == 5).FirstOrDefault();
                                    if (resume6 != null)
                                    {
                                        LiteralSix1.Text = resume6.StartTime;
                                        LiteralSix2.Text = resume6.EndTime;
                                        LiteralSix3.Text = resume6.Where;
                                        LiteralSix4.Text = resume6.Witness;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}